package com.group6.service.impl;

import com.group6.mapper.UserMapper;
import com.group6.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private  UserMapper userMapper;

    @Override
    public List<User> userList() {
        return userMapper.selectList(null);
    }

    @Override
    public String userAdd(UserVo userVo) {
        User user = new User();
        user.setName(userVo.getName());
        user.setAge(userVo.getAge());
        user.setEmail(userVo.getEmail());
        user.setId(userVo.getId());
        int result = userMapper.insert(user);
         if(result > 0){
             return "添加成功";
         }else {
             return "添加失败";
         }

    }

    @Override
    public String userUpdate(User user) {
        User user1 = new User();
        user1.setId(user.getId());
        user1.setName(user.getName());
        user1.setAge(user.getAge());
        user1.setEmail(user.getEmail());
        int result = userMapper.updateById(user1);
        if (result > 0){
            return "修改成功";
        }else {
            return "修改失败";
        }

    }
}
